<?php
namespace app\navs\loglic;

class Fields
{
    /**
    * 返回所有表单字段
    * @version 1.6.0 首次引入
    * @return array 表单字段数组列表（DcBuildForm）
    */
    public function keys($data=[])
    {
        $fields = $this->items($data);
        
        foreach($fields as $key=>$value){
            if(!isset($value['type'])){
                unset($fields[$key]);
            }else{
                if($value['type']=='html'){
                    unset($fields[$key]);
                }
            }
        }
        
        return array_keys($fields);
    }
    
    /**
    * 表单字段通用属性处理
    * @version 1.6.0 首次引入
    * @param array $data 可选;初始数据;默认：空
    * @return array 表单字段数组列表（DcBuildForm）
    */
    public function items($data=[])
    {
        //获取表单字段列表
        $fields = $this->fields($data);
        //增加字段的相同属性值
        foreach($fields as $key=>$value){
            $fields[$key]['class_left']  = 'col-12';
            $fields[$key]['class_right'] = 'col-12';
            $fields[$key]['class_tips']  = '';
        }
        //表单字段（格式化）
        return DcFormItems($fields);
    }
    
    /**
    * 表格选项通用属性处理
    * @version 1.6.0 首次引入
    * @param array $data 可选;初始数据;默认：空
    * @return array 表格列字段属性（DcBuildTable）
    */
    public function columns($data=[])
    {
        $columns = DcTableColumns( $this->fields($data) );
        
        $columns['operate']['data-events']    = 'daicuo.navs.events';
        
        $columns['operate']['data-formatter'] = 'daicuo.navs.operate';
        
        return $columns;
    }
    
    //定义文章的字段
    public function fields($data)
    {
        return [
            'html_1' => [
                'type'  => 'html',
                'value' => '<div class="row"><div class="col-12 col-md-8">',
                'order' => 0,
            ],
            'op_id' => [
                'type'            => 'hidden',
                'value'           => $data['op_id'],
                'data-filter'     => false,
                'data-visible'    => true,
                'data-width'      => '80',
                'data-sortable'   => true,
            ],
            'nav_text' => [
                'type'            => 'text',
                'value'           => $data['nav_text'],
                'required'        => true,
                'data-filter'     => false,
                'data-visible'    => true,
                'data-align'      => 'left',
            ],
            'op_status_text' => [
                'data-title'      => lang('op_status'),
                'data-visible'    => true,
                'data-width'      => '100',
            ],
            'nav_ico' => [
                'type'            => 'text',
                'value'           => $data['nav_ico'],
                'data-filter'     => false,
                'data-visible'    => true,
                'data-width'      => '100',
                'data-formatter'  => 'daicuo.table.ico',
            ],
            'nav_active' => [
                'type'            => 'text',
                'value'           => $data['nav_active'],
                'data-filter'     => false,
                'data-visible'    => true,
                'data-width'      => '100',
            ],
            'nav_parent' => [
                'type'            => 'select',
                'value'           => intval($data['nav_parent']),
                'option'          => DcNavOption(),
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'nav_target' => [
                'type'            => 'select',
                'value'           => $data['nav_target'],
                'option'          => ['_blank'=>lang('target_option_0'),
                                      '_self'=>lang('target_option_1'),
                                      '_parent'=>lang('target_option_2'),
                                      '_top'=>lang('target_option_3'),
                                      '_new'=>lang('target_option_4')
                                     ],
                'data-filter'     => false,
                'data-visible'    => true,
                'data-width'      => '100',
            ],
            'nav_type' => [
                'type'            => 'select',
                'value'           => $data['nav_type'],
                'option'          => [
                                      'link'=>lang('nav_type_option_0'),
                                      'addon'=>lang('nav_type_option_1')
                                     ],
                'data-filter'     => false,
                'data-visible'    => true,
                'data-width'      => '100',
            ],
            'nav_url' => [
                'type'            => 'text',
                'value'           => $data['nav_url'],
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'nav_module' => [
                'type'            => 'text',
                'value'           => $data['nav_module'],
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'nav_controll' => [
                'type'            => 'text',
                'value'           => $data['nav_controll'],
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'nav_action' => [
                'type'            => 'text',
                'value'           => $data['nav_action'],
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'nav_params' => [
                'type'            => 'text',
                'value'           => $data['nav_params'],
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'nav_suffix' => [
                'type'            => 'text',
                'value'           => $data['nav_suffix'],
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'html_2'      => [
                'type'  => 'html',
                'value' => '</div><div class="col-12 col-md-4">',
                'order' => 250,
            ],
            'op_status' => [
                'type'            => 'select',
                'value'           => DcEmpty($data['op_status'],'normal'),
                'option'          => ['normal'=>lang('normal'),'hidden'=>lang('hidden')],
                'data-filter'     => true,
                'data-visible'    => false,
            ],
            'op_order' => [
                'type'            => 'text',
                'value'           => intval($data['op_order']),
                'data-filter'     => false,
                'data-visible'    => true,
                'data-sortable'   => true,
                'data-width'      => '100',
                'data-formatter'  => 'daicuo.table.sort',
            ],
            'op_module' => [
                'type'            => 'text',
                'value'           => DcEmpty($data['op_module'],'common'),
                'data-filter'     => true,
                'data-visible'    => true,
                'data-width'      => '100',
                'data-formatter'  => 'daicuo.navs.formatter',
            ],
            'op_controll' => [
                'type'            => 'text',
                'value'           => DcEmpty($data['op_controll'],'navbar'),
                'data-filter'     => true,
                'data-visible'    => true,
                'data-width'      => '100',
                'data-formatter'  => 'daicuo.navs.formatter',
            ],
            'op_action' => [
                'type'            => 'text',
                'value'           => DcEmpty($data['op_action'],'header'),
                'data-filter'     => true,
                'data-visible'    => true,
                'data-width'      => '100',
                'data-formatter'  => 'daicuo.navs.formatter',
            ],
            'html_3'      => [
              'type'  => 'html',
              'value' => '</div></div>',
              'order' => 500,
            ]
        ];
    }
}